<?php

namespace mbilling\BillingBundle\Model;

use Doctrine\ORM\EntityManager;
use mbilling\BillingBundle\Entity\usersBills;


Class UsersBillsModel
{
    protected $em;

    public function __construct(EntityManager $em)
    {
        $this->em = $em;
    }
    
    public function findAll()
    {
        $bills = $this->em->getRepository('BillingBundle:usersBills')->findAll();
        return $bills;
    }
    
    public function findByUserId($user_id)
    {
        $bills = $this->em->getRepository('BillingBundle:usersBills')->findBy(array('user_id' => $user_id));
        return $bills;
    }

    public function findByOrderId($order_id)
    {
        $bill = $this->em->getRepository('BillingBundle:usersBills')->findOneBy(array('order_id' => $order_id));
        return $bill;
    }
    
    public function findByPK($bill_id)
    {
        $bill = $this->em->find('BillingBundle:usersBills', $bill_id);
        return $bill;
    }

    public function findNotReal($order_id)
    {
        $bills = $this->em->getRepository('BillingBundle:usersBills')->findBy(array('order_id' => $order_id, 'is_real' => '0'));
        return $bills;
    }
    
    public function create($oEntity)
    {
        $this->em->persist($oEntity);
        $this->em->flush();
    }

    public function removeByPK($bill_id)
    {
        $bill = $this->em->find('BillingBundle:usersBills', $bill_id);
        $this->em->remove($bill);
        $this->em->flush();
    } 

    public function removeByOrderId($order_id)
    {
        $bill = $this->em->getRepository('BillingBundle:usersBills')->findOneBy(array('order_id' => $order_id));
        $this->em->remove($bill);
        $this->em->flush();
    }
}
?>
